﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace PlanningDepartment
{
    public partial class FrKHTheoDoi : Form
    {
        public FrKHTheoDoi()
        {
            InitializeComponent();
        }

        private SqlConnection Conn;
        private Process prs = new Process();

        private DataSet ds = new DataSet();
        private string string_temp = null, child = " - ", Serial1, MaSP1, MaCT1, Datebegin, Dateend, GhiChu1, MaKH1, TenKH1, KhuVuc1, ID, TenCT1, TenSP1, CDay1, CRong1, CDai1, SoLuong1;
        private int i = 0, int_temp = 0;
        private void Load_()
        {
            SqlCommand cmd = new SqlCommand();
            Conn = prs.Connect_DBScansia();
            Conn.Open();
            DataSet ds = new DataSet();
            try
            {

                cmd.CommandText = "select MaSP,TenSP from dbo.Load_cbSP";
                cmd.Connection = Conn;
                SqlDataReader rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    cbx_TenSP.Items.Add(rd[1].ToString() + " - " + rd[0].ToString());
                    //cb_MaSP_edit.Items.Add(rd[1].ToString() + " - " + rd[0].ToString());
                }

                rd.Close();
                string_temp = @"select dbo.Load_CTSP_Mua.MaSP,dbo.Load_CTSP_Mua.TenChiTiet+' - '+dbo.Load_CTSP_Mua.MaChiTiet,ChieuDaySC,ChieuRongSC,ChieuDaiSC from dbo.Load_CTSP_Mua
                                group by dbo.Load_CTSP_Mua.MaSP,dbo.Load_CTSP_Mua.TenChiTiet+' - '+dbo.Load_CTSP_Mua.MaChiTiet,ChieuDaySC,ChieuRongSC,ChieuDaiSC";
                ds = prs.dts(string_temp, Conn, ds);
                dataGridView_LoadSP.DataSource = ds.Tables[0];
                string[] arr_LoaiGo = new string[] { "KV1 Ripsaw", "KV1 Tan Dung", "KV1 Long", "KV1 Uon", "KV1 Cat KT", "KV1 Cat Hoi", "KV1 Xe", "KV1 Truoc Bao", "KV1 Sau Bao", "KV1 Cha Nham", "KV1 Tram Tret", "KV1 KTG", "Dinh Vi", "KV1 Ghep", "KV1 KTG", "KV2 Dinh Vi", "KV2 Tram Tret", "KV2 Tan Dung", "KV2 CNC", "KV2 Tai Che", "KV3 Kho Cho Rap", "KV3 Lap Rap", "KV3 Kho Tam", "KV4 Sau Nhung", "KV4 Xuong Chuyen", "KV4 Tan Dung", "KV4 Tai Che", "KV5 Dong Goi" };
                for (i = 0; i < arr_LoaiGo.Length; i++)
                {

                    cbx_KhuVuc.Items.Add(arr_LoaiGo[i].ToString());
                    //cb_KhuVuc_edit.Items.Add(arr_LoaiGo[i].ToString());
                    //cb_KhuVucBK.Items.Add(arr_LoaiGo[i].ToString());
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                Conn.Close();

                cmd.Dispose();
            }
        }
        private void cbx_TenSP_SelectedIndexChanged(object sender, EventArgs e)
        {
            MaSP1 = prs.substring_right(cbx_TenSP.Text, child);
            cbx_ChiTiet.Items.Clear();

            cbx_ChiTiet.Text = "";
            for (i = dataGridView_LoadSP.Rows.Count - 2; i >= 0; i--)
            {
                if (MaSP1 == dataGridView_LoadSP.Rows[i].Cells[0].Value.ToString())
                {
                    cbx_ChiTiet.Items.Add(dataGridView_LoadSP.Rows[i].Cells[1].Value.ToString());
                }
            }
        }

        private void FrKHTheoDoi_Load(object sender, EventArgs e)
        {
            Load_();
        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void bt_add_input_Click(object sender, EventArgs e)
        {

        }
    }
}
